import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.io.entity.EntityUtils;

import java.io.IOException;

public class get {
    public static void main(String[] args) {
//        创建HttpClient对象
         CloseableHttpClient httpclients = HttpClients.createDefault();
//        创造HttpGet对象，设置url地址
         HttpGet httpGet = new HttpGet("http://www.itcast.cn");

//        使用HTTP Client发起请求，获取response
        CloseableHttpResponse response=null;
        try {
            response = httpclients.execute(httpGet);
            if (response.getCode()==200) {
                 String utf8 = EntityUtils.toString(response.getEntity(), "utf8");
                System.out.println(utf8.length());
            }

        } catch (Exception e) {
            throw new RuntimeException();
        }finally {

            try {
                response.close();
                httpclients.close();
            } catch (IOException e) {
                throw new RuntimeException();
            }

        }
//        解析响应
    }
}
